package com.egao.api.controller.nont;


import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.system.entity.User;
import com.egao.common.system.service.OperRecordService;
import com.egao.orderB.biz.OceanBiz;
import com.egao.orderB.biz.OceanFeeBiz;
import com.egao.orderB.entity.Ocean;
import com.egao.orderB.entity.OceanFee;
import com.egao.orderB.service.OceanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 * https://francjc.com:4332/swagger-ui.html
 */
@RequestMapping("/api/nt/ocean")
@RestController
@Api(value = "订舱管理没有token",tags = {"订舱管理没有token"})
public class ApiOceanNtController extends BaseController {

    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private OceanService oceanService;
    @Autowired
    private OceanBiz oceanBiz;
    @Autowired
    private OceanFeeBiz oceanFeeBiz;


    /**
     * 订舱管理
     */
    @OperLog(value = "订舱管理", desc = "导出费用", result = true)
    @ApiOperation(value ="导出费用订舱费用",notes = "" +
            "id:id\n" +
            "",httpMethod = "GET")
    @GetMapping("/exportOcean")
    public void exportOcean(Ocean ocean, HttpServletResponse response) throws Exception  {
        try {
            oceanService.exportOcean(ocean, response);
        } catch (Exception e) {
            response.setContentType("text/html; charset=UTF-8");
            response.getWriter().println("没有对应的数据哦,请再次查询!");
        }
    }

    /**
     * 订舱管理
     */
    @OperLog(value = "订舱管理", desc = "导出财务费用", result = true)
    @ApiOperation(value ="导出财务费用",notes = "" +
            "date1:时间1\n" +
            "date2:时间2\n" +
            "",httpMethod = "GET")
    @GetMapping("/exportOceanFinance")
    public void exportOceanFinance(Ocean ocean, HttpServletResponse response) throws Exception  {
        List<Ocean> list = oceanBiz.list(ocean, new User(1));
        if (list != null && list.size() > 0) {
            for (Ocean ocean1 : list) {
                OceanFee oceanFee = new OceanFee();
                oceanFee.setOceanId(ocean1.getId());
                ocean1.setOceanFeeList(oceanFeeBiz.listExcel(oceanFee, new User(1)));
            }
            try {
                oceanService.exportOceanFinance(list, response);
            } catch (Exception e) {
                e.printStackTrace();
                response.setContentType("text/html; charset=UTF-8");
                response.getWriter().println("没有对应的数据哦,请再次查询!");
            }
        } else {
            response.setContentType("text/html; charset=UTF-8");
            response.getWriter().println("没有对应的数据哦,请再次查询!");
        }
    }

}
